 <script type="text/javascript" src="easyui/province.js"></script>
 <link rel="stylesheet" href="themes/editor/default.css" />
<script charset="utf-8" type="text/javascript" src="js/editor/editor-min.js"></script>
<script charset="utf-8"  type="text/javascript" src="js/editor/editor_zh_CN.js"></script>
 <form id="addCustomerfm" method="post" novalidate>
        <div class="ftitle">必填信息</div>
        	<input name="id" type="hidden">
            <div class="fitem">
                <label>姓名:</label>
                <input name="name" class="easyui-validatebox" required="true">
            </div>
            <div class="fitem">
                <label>性别:</label>
                <select name="sex">
                	<option value="MAN" selected="selected">男</option>
                	<option value="WOMAN">女</option>
                </select>
            </div>
            <div class="fitem">
           			 <label>省份:</label>
					<select name="province" id="areaProvince" class="text" onchange="PC.initCity('areaProvince','areaCity','');">					
                   </select>
                   <label>城市:</label>
                   <select name="city" id="areaCity" class="text"></select>
            </div>
           <div class="ftitle">可选信息</div>
           <div class="fitem">
                <label>头像:</label>
				<input class="ke-input-text" type="text" id="customerHead" value="" readonly="readonly" /> <input type="button" id="uploadButton" value="选择文件" />
				<input name="attachementId" id="attachementId" type="hidden">
           </div>
           <div class="headPic" id="headPic">
           </div>
            <div class="fitem">
                <label>客户类型:</label>
                <input id="customerType" name="customerType">
            </div>
            <div class="fitem">
                <label>整形项目:</label>
                <input id="customerItems" name="items">
            </div>
            <div class="fitem">
                <label>年龄:</label>
                <input name="age"  class="easyui-numberbox">
            </div>
          	<div class="fitem">
                <label>电话:</label>
                <input name="cell">
            </div>
            <div class="fitem">
                <label>email:</label>
                <input name="email" class="easyui-validatebox" validType="email" >
            </div>
            <div class="fitem">
                <label>QQ:</label>
                <input name="qq">
            </div>
            <div class="fitem">
                <label>微信:</label>
                <input name="weixin">
            </div> 
			<div class="fitem">
                <label>职业:</label>
                <input name="work">
            </div>                                                       
        </form>
    <div id="customer-buttons">
        <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-ok" onclick="javascript:addCustomerJs.saveCustomer()">确定</a>
    </div>
<script type="text/javascript">
(function(addCustomerJs, $, undefined ) {  
	addCustomerJs.init = function(){
		workbenchJs.loadData("dispatch/manage/item/all",addCustomerJs.loadItemsResult,"查询整形项目");
		workbenchJs.loadData("dispatch/manage/customerType/all",addCustomerJs.loadCustomerType,"查询客户类型");
		PC.initProvince("areaProvince","上海");
		PC.initCity("areaProvince","areaCity","上海");
		var action = customerActionJs.getCustomerAction();
		 
		if(action == "add")
		{
			addCustomer();
		}else
		{
			editCustomer();
		}
		
		var uploadbutton = KindEditor.uploadbutton({
			button : KindEditor('#uploadButton'),
			 fieldName : 'cfile',
			 url :'file/upload?type=customer',
			 afterUpload : function(data) {
				 //var payload = jQuery.parseJSON(data);
				 if(data.error == '0')
				{
					 $('#customerHead').val(data.name);
					 $('#attachementId').val(data.url);
					 var img = '<img src="'+data.url+'" style="width:150px;height:150px"/>';
					 $('#headPic').html(img);
				}else
				{
					$.messager.alert("上传错误",data.message);
				}
				 
			 },

		});
		
		uploadbutton.fileBox.change(function(e) {
			 uploadbutton.submit();
		 });
		
	};
	 
	addCustomerJs.loadItemsResult = function(result){
		var payload = jQuery.parseJSON(result.payload.value);
		$('#customerItems').combobox({
			url:null,
			valueField:'name',
			textField:'name',
			multiple:true,
			panelHeight:'auto',
			data:payload
		});
		var action = customerActionJs.getCustomerAction();
		if(action != "add")
		{
			var row = customerActionJs.getEditCustomerData();
        	if(row.items != "")
        	{
    			var array = row.items.split(",");

    	    	var i = new Array();
    	    	$(array).each(function(index){
    	    		i[index] = array[index];
    	    	});
    	    	
           		$('#customerItems').combobox('setValues',i);
        	}
		}
	};
	addCustomerJs.loadCustomerType = function(result){
		
		var payload = jQuery.parseJSON(result.payload.value);
		$('#customerType').combobox({
			url:null,
			valueField:'name',
			textField:'name',
			multiple:false,
			panelHeight:'auto',
			data:payload
		});
		var action = customerActionJs.getCustomerAction();
		if(action != "add")
		{
			var row = customerActionJs.getEditCustomerData();
			$('#customerType').combobox('setValue',row.customerType);
		}
	};
    var customerActionurl;
    function addCustomer(){
        $('#addCustomerfm').form('clear');
        customerActionurl = 'dispatch/customer/add';
    };
    function editCustomer(){
        var row = customerActionJs.getEditCustomerData();
        $('#addCustomerfm').form('clear');
        $('#addCustomerfm').form('load',row);
        PC.initProvince("areaProvince",row.province);
        PC.initCity("areaProvince","areaCity",row.city);
        customerActionurl = 'dispatch/customer/update';
    };
    addCustomerJs.saveCustomer = function(){
		var customer = {};
		customer.id = $("#addCustomerfm input[name='id']").val();
		customer.name = $("#addCustomerfm input[name='name']").val();
		customer.sex = $("#addCustomerfm select[name='sex']").val();
		customer.province = $("#addCustomerfm select[name='province']").val();
		customer.city = $("#addCustomerfm select[name='city']").val();
		customer.age = parseInt($("#addCustomerfm input[name='age']").val());
		customer.cell = $("#addCustomerfm input[name='cell']").val();
		customer.email = $("#addCustomerfm input[name='email']").val();
		customer.qq = $("#addCustomerfm input[name='qq']").val();
		customer.weixin = $("#addCustomerfm input[name='weixin']").val();
		customer.work = $("#addCustomerfm input[name='work']").val();
		customer.customerType = $("#addCustomerfm input[name='customerType']").val();
		customer.image = $("#attachementId").val();
		
    	var items = "";
    	var r = $('#customerItems').combobox('getValues');
    	$(r).each(function(index){
    		if(items != "")items += ','+r[index];
    		else items = r[index];
    	});
    	customer.items = items;
    	
    	var str = $.toJSON(customer);
    	str = 'parameters='+str;
    	
    	if($('#addCustomerfm').form('validate'))
    	{
    		$.ajax({
                type: "post",
                url: customerActionurl,
                dataType:"json",
                data: str,
                cache: false,
                success: function (result) {
                	var res = result.result;
                    if(res == "SUCCESS")
                    {
                    	customerActionJs.CustomerActionCompelete(result);
                    }else if(res == "NOT_AUTHORIZED")
                    {
                    	$.messager.alert("Error","您没有权限 添加/修改用户信息");
                    }else if(res == "COMPONENT_ERROR")
                    {
                    	$.messager.alert("Error",result.payload.value);
                    }else
                    {
                    	$.messager.alert("Error",result.result);
                    }
                    
                }
                
            });
    	}
    };
}( window.addCustomerJs = window.addCustomerJs || {}, jQuery ));

$(function(){
	addCustomerJs.init();
}); 
	</script>
    <style type="text/css">
    	.headPic{
    		float:right;
    		width:160px;
    		height:160px;
    		border:1px solid #e6e6e6;
    	}
        
    </style>